<?php



$nomRep = 'test_typer';
$rep = opendir($nomRep); 

$resultat = "\n\n\t Nom Programme \t | \t ETAT GCC \t | \t ETAT MINIC \t | \t ETAT GLOBALE \n";
$resultat .="-------------------------------------------------------------------------------------------------------- \n"; 

$nbProgramme = 0;

$nbProgramme_succes = 0;
$nbProgramme_fail = 0;


while($file = readdir($rep)) {
	
	//On veut des fichier C uniquement
	if($file != '.' && $file != '..' && !is_dir($nomRep."/".$file)){
		if(preg_match("#.c#", $file)){		
			
			$nbProgramme++;
		
			if(strlen($file)<11)
				$resultat.="| ". $file . "\t\t : ";
			else if(strlen($file)<21)
				$resultat.="| ". $file . "\t : ";
			else
				$resultat.="| ". $file . " : ";

			$succes1 = false;		
			
			$exec = exec("gcc ".$nomRep."/".$file ,$op, $code);			
			if($code == 0){
				$succes1 = true;
				$resultat.= "\t SUCCES \t | \t ";		
			}else
				$resultat.= "\t FAIL \t\t | \t ";	

			$exec = exec("../src-old/minic -type_only ".$nomRep."/".$file ,$op, $code);
			if($code == 2){
				$resultat.="!!ANOMALY!!\t | \t !! ANOMALY !! \t".$code;
				$nbProgramme_fail++;
			}else if($code == 0 && $succes1){
				$resultat.="SUCCES \t | \t SUCESS \t".$code;
				$nbProgramme_succes++;
			}else if($code == 0 && !$succes1){
				$resultat.="SUCCES  \t | \t !! FAIL !! \t".$code;
				$nbProgramme_fail++;
			}else if($code != 0 && !$succes1){
				$resultat.="FAIL \t\t | \t SUCESS \t".$code;
				$nbProgramme_succes++;
			}else{
				$resultat.="FAIL \t\t | \t !! FAIL !! \t".$code;
				$nbProgramme_fail++;
			}

			$resultat.="\n";
		}
	}
}

closedir($rep);

$resultat.="-----------------\n\n";
$resultat.="Nombre de programme Teste \t:\t $nbProgramme\n";
$resultat.="Nombre de programme Succes \t:\t $nbProgramme_succes sur $nbProgramme\n";
$resultat.="Nombre de programme Fail \t:\t $nbProgramme_fail sur $nbProgramme\n";
$resultat.="\nNote \t\t\t\t:\t ".(($nbProgramme_succes/$nbProgramme)*100)."%\n";

echo $resultat;

?>
